package com.briansteen.sketches;

import java.util.ConcurrentModificationException;
import java.util.Vector;

import berlinatyourfingertips.ua.UAListener;
import berlinatyourfingertips.ua.UAResult;
import berlinatyourfingertips.ua.apis.UAUpdatingTwitter;

import cc.creativecomputing.CCApp;
import cc.creativecomputing.CCApplicationManager;
import cc.creativecomputing.CCApplicationSettings;
import cc.creativecomputing.graphics.font.CCFontIO;

@SuppressWarnings("serial")
public class FontPainterAnim extends CCApp implements UAListener {
	
	private Vector<TweetingPainterFaceEntry> colors = new Vector<TweetingPainterFaceEntry>();
	
	public void setup() {
		g.clearColor(1f);
		
		for(int i=0;i<CCFontIO.list().length;i++) {
			System.out.println(CCFontIO.list()[i]);
		}

		UAUpdatingTwitter twitter = new UAUpdatingTwitter(this, 60000);
		twitter.start();
		
//		for(int i = 0; i < 100; i++) colors.add(new TweetingPainterFaceEntry("HALLO 123 LKJHDFkjdhsfk", width, height));
	}
	
	public void draw(){		
		
		g.noDepthTest();
		
		try {
			for(int i = 0; i < colors.size(); i++) {
				if(colors.get(i).isDone()) colors.remove(i);
				else colors.get(i).draw(g);
			}
		} catch(ConcurrentModificationException eee) {}
	}
	
	public FontPainterAnim(CCApplicationSettings theSettings) {
		super(theSettings);
	}

	public void newElement(UAResult uar) {
		if(colors.size() < 20) {
			System.out.println("Adding "+uar.getMessage());
			
			colors.add(new TweetingPainterFaceEntry(uar.getMessage(), width, height));			
		}
	}

	public void removeElement(UAResult uar) {
		// TODO Auto-generated method stub
		
	}
	
	public static void main(String[] args){
		final CCApplicationManager<FontPainterAnim> _myManager = new CCApplicationManager<FontPainterAnim>(FontPainterAnim.class);
		_myManager.settings().antialiasing(8);
		_myManager.settings().size(1400, 1000);
		_myManager.start();
	}	
}
